{extend name='public/content'}

{block name="title"}
	商品详情
{/block}

{block name="body"}
	<div class="client"></div>
		对方的id	
	<input type="text" name="touid">
		消息内容
	<input type="text" name="msg">

	<div class="xiaoxi">
		<div> </div>
	</div>

<button class="fasongxiaoi">发送消息</button>
<button class="shifozaixiang">是否在线</button>

{/block}

{block name="script"}
 	<script type="text/javascript">
 		require(['jquery'], function () {

 			var dom={
			       base:"http://127.0.0.1/",
			       soketbase:"ws://127.0.0.1:7272/",
			   }
			   var i=0;
			    ws = new WebSocket(dom.soketbase);
		        ws.onopen = onopen;
		        ws.onmessage = onmessage;
		         function onmessage(e){       
		           var dat=e.data; 
		           console.log(dat);
		           var msg = $.parseJSON(dat);
		           if(msg.type==1){
		           		//绑定uid
		           		$('.client').text(msg.cliet);	
		           		$.ajax({
		           			url: "{:url('work/binduidbyclientadmin')}",
		           			type: 'GET',
		           			dataType: 'json',
		           			data: {client:msg.cliet,uid:"{$kefu1}"},
		           		})
		           		.done(function() {
		           			
		           		})
		           		.fail(function() {
		           			
		           		})
		           		.always(function() {
		           			 
		           		});
		           		
		           }
		            console.dir(dat);		
		           if(msg.type==2){
		           		$('.xiaoxi').append(msg.msg)
		           		$('input[name=touid]').val(msg.fromuid)
		           }
		         }
		         
		         function onopen(e){ 
		         
		         }

		         $('.fasongxiaoi').click(function() {
		         	var msg = $('input[name=msg]').val();
		         	var fromuid="{$kefu1}";
		         	var touid  = $('input[name=touid]').val();
		         	$.ajax({
		         		url: "{:url('index/work/sedmsuid')}",
		         		type: 'GET',
		         		dataType: 'json',
		         		data: {fromuid:fromuid,touid:touid,msg:msg,type:2,userinfo:"用户名"},
		         	})
		         	.done(function() {
		         		
		         	})
		         	.fail(function() {
		         		
		         	})
		         	.always(function() {
		         		
		         	});
		         });

		        $('.shifozaixiang').click(function() {
		       	 var touid =$('input[name=touid]').val();
		         	$.ajax({
		         		url: "{:url('index/work/isonline')}",
		         		type: 'GET',
		         		dataType: 'json',
		         		data: {touid:touid},
		         	})
		         	.done(function($data) {
		         		alert($data);
		         	})
		         	.fail(function() {
		         		
		         	})
		         	.always(function() {
		         		
		         	});


		         })
		         
 		})
 	</script>
{/block}

{block name="style"}
 <style type="text/css">
 	
 </style>
{/block}